package com.uenpay.oem.ui.auth;

import com.socks.library.KLog;
import com.uenpay.im.entities.QYXUserEntity;
import com.uenpay.oem.data.bean.UserIdCardInfo;
import com.uenpay.oem.data.model.IUserAuthModel;
import com.uenpay.oem.data.modelImpl.UserAuthModel;
import com.uenpay.util.net.listener.HttpOnNextListener;
import com.uenpay.util.net.listener.HttpResultListener;

/**
 * Author: liulou
 * Date: 2017/6/18.
 * desc:
 */

public class AuthConfirmPresenter implements AuthComfirmContract.Presenter {

    private AuthComfirmContract.View mConfirmView;
    private IUserAuthModel mAuthModel;

    public AuthConfirmPresenter(AuthComfirmContract.View view) {
        mConfirmView = view;
        mAuthModel = new UserAuthModel();
    }

    @Override
    public void confirmAuth(final UserIdCardInfo info) {
        if (info == null) return;
        mAuthModel.userInfoQuery(new HttpOnNextListener<QYXUserEntity>() {
            @Override
            public void onNext(QYXUserEntity qyxUserEntity) {
                userRealNameAuth(qyxUserEntity, info);
            }
        });

    }

    private void userRealNameAuth(QYXUserEntity qyxUserEntity, UserIdCardInfo idCardInfo) {
        mAuthModel.userRealNameAuth(qyxUserEntity, idCardInfo, new HttpResultListener() {
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                KLog.d("认证失败：" + e.getMessage());
                mConfirmView.showAuthResult(false);
            }

            @Override
            public void onComplete() {
                super.onComplete();
                KLog.d("实名认证成功");
                mConfirmView.showAuthResult(true);
            }
        });
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onDestroy() {

    }
}
